package com.zzx.test.thread.juc;

import java.util.concurrent.TimeUnit;

/**
 * @ClassName: PhoneTest1
 * @Description: synchronized锁测试类
 * @Author zhouzhixin
 * @Date 2021/11/3
 * @Version 1.0
 */
public class PhoneTest1 {

    public static void main(String[] args) {
        Phone1 phone = new Phone1();

        new Thread(() -> {
            phone.sendSMS();
        }, "A").start();

        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        new Thread(() -> {
            phone.call();
        }, "B").start();
    }

}

class Phone1 {

    public synchronized void sendSMS() {
        try {
            TimeUnit.SECONDS.sleep(3);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("发短信");
    }

    public static synchronized void call() {
        System.out.println("打电话");
    }

}
